package cn.lx.es.query.processor;

import cn.lx.es.query.annotation.SearchProcessor;
import cn.lx.es.query.annotation.WildcardSearch;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

import java.lang.reflect.Field;

/**
 * 内置处理器 - 通配符搜索处理器
 */
@SearchProcessor
public class SearchWildcardProcessor implements SearchAnnotationProcessor<WildcardSearch> {
    @Override
    public void process(WildcardSearch annotation, Field field, Object value, BoolQueryBuilder boolQueryBuilder) {
        if (value != null) {
            boolQueryBuilder.must(QueryBuilders.wildcardQuery(field.getName(), value.toString()));
        }
    }
    @Override
    public Class<WildcardSearch> getAnnotationType() {
        return WildcardSearch.class;
    }
}
